package router

import (
	_ "crow-samba/docs"
	"github.com/gin-gonic/gin"
	swaggerFiles "github.com/swaggo/files"
	ginSwagger "github.com/swaggo/gin-swagger"
	"net/http"
)

func initRouter() (r *gin.Engine) {
	r = gin.Default()
	return r
}

func ServerRouter() {
	r := initRouter()
	r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
	//创建一个groupV1组，里边放一个检查存活的接口
	groupV1 := r.Group("/api/v1")
	{
		groupV1.GET("/ping", Ping)
		groupV1.GET("/version", Version)
		groupV1.GET("/liubei", LiuBei) //这是一个测试接口

		//登录
		groupV1.POST("/login", Login)           //登录服务
		groupV1.POST("/login/refresh", Refresh) //生成新token

		//用户接口
		groupV1.GET("/user/list", user(), GetSambaUsers)    //获取samba用户
		groupV1.POST("/user", user(), AddSambaUser)         //添加samba用户
		groupV1.DELETE("/user/:user_name", DeleteSambaUser) //删除samba用户

		//配置文件接口
		groupV1.GET("/conf", user(), GetSambaConf)    //获取位置文件
		groupV1.POST("/conf", user(), WriteSambaConf) //写入配置文件（仅作为调试或应急处理）

		//目录接口
		groupV1.POST("/directory", user(), AddDirectories)             //添加新共享目录（此处暂时不添加权限）
		groupV1.GET("/directory/List", user(), GetDirectoryList)       //获取目录列表
		groupV1.GET("/directory", user(), GetDirectory)                //获取指定目录信息
		groupV1.DELETE("/directory/:dir_tag", user(), DeleteDirectory) //取消共享目录

		//目录接口-写用户
		groupV1.PUT("/directory/writers", user(), SetDirectoryWriter)                    //重置写用户
		groupV1.DELETE("/directory/:dir_tag/writers", user(), RemoveWriterFromDirectory) //移除写用户
		groupV1.POST("/directory/writers", user(), AddWriterToDirectory)                 //增加写用户

	}

	//前端相关路由
	webGroup := r.Group("")
	{
		webGroup.GET("/", indexHtml)
		webGroup.StaticFS("/js", http.Dir("./web/js"))
		//r.StaticFile("/deamon.js", "./web/deamon.js")
	}

	r.Run(":1840")
}
